const IntValueSchema = {
  name: 'IntValue',
  properties: {
    value: 'int'
  }
}

const VersionSchema = {
  name: 'Version',
  primaryKey: 'id',
  properties: {
    id: 'int',
    appName: { type: 'string', indexed: true },
    appId: { type: 'string', indexed: true },
    versionType: { type: 'string?', indexed: true }, // patch,res,apk
    enable: { type: 'bool', indexed: true },
    versionName: { type: 'string?', indexed: true },
    versionCode: { type: 'int?', indexed: true },
    createTime: { type: 'date', indexed: true },
    targetVersion: 'IntValue[]',
    url: { type: 'string' },
    force: {type: 'bool', default: false},
    desc: 'string?'
  }
}

const AutoIncVersionId = params => {
  const realm = require('.')
  let versions = realm.objects('Version').sorted('id', true)
  return versions.length > 0 ? versions[0].id + 1 : 1
}

module.exports = { VersionSchema, IntValueSchema, AutoIncVersionId }
